//package com.bsj.media.network.websocket;
//
//import com.alibaba.fastjson.JSONObject;
//import com.bsj.consumerQ.until.ExceptionUntil;
//import com.bsj.media.init.websocket.AudioDataSessionHandle;
//import com.bsj.media.init.websocket.CmdSessionCheckThread;
//import com.bsj.media.init.websocket.MediaSocketChannel;
//import com.bsj.power.common.config.global.JsonResultExpend;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import org.springframework.util.LinkedMultiValueMap;
//import org.springframework.util.MultiValueMap;
//import org.yeauty.annotation.*;
//import org.yeauty.pojo.Session;
//
//import java.io.IOException;
//import java.util.List;
//
//@ServerEndpoint(value = "/webSocket/media", port = "12969")
//@Slf4j
//@Component
//public class MediaSocket {
//
//    @Autowired
//    private CmdSessionCheckThread cmdSessionCheckThread;
//
//    @OnOpen
//    public void onOpen(Session session, @RequestParam MultiValueMap reqMap) {
//        LinkedMultiValueMap<String, String> linkedMultiValueMap = (LinkedMultiValueMap) reqMap;
//        List<String> stringList = linkedMultiValueMap.get("simChannel");
//        if (stringList != null && !stringList.isEmpty()) {
//            String simChannel = stringList.get(0);
//            if (StringUtils.isBlank(simChannel)) {
//                session.sendText(JSONObject.toJSONString(JsonResultExpend.fail("无效参数")));
//                return;
//            }
//            //TODO 保证每次一个设备进行对讲
//            MediaSocketChannel.push(simChannel, session);
//            AudioDataSessionHandle.addData(simChannel, session);
//            cmdSessionCheckThread.push(session);
//        }
//    }
//
//    @OnClose
//    public void onClose(Session session) throws IOException {
//        cmdSessionCheckThread.del(session);
//        AudioDataSessionHandle.delAllAudioCached(session);
//    }
//
//    @OnError
//    public void onError(Session session, Throwable throwable) {
//        log.error("websocket异常:" + ExceptionUntil.getErrorStr(throwable));
//        cmdSessionCheckThread.del(session);
//        AudioDataSessionHandle.delAllAudioCached(session);
//    }
//
//    @OnBinary
//    public void onBinary(Session session, byte[] data) {
//        MediaSocketChannel.pushData(session, data);
//    }
//}
